<template>
	<view class="" style="height:100%;">
		<u-back-top :scroll-top="scrollTop"></u-back-top>
		<u-sticky>
			<view class="">
				<u-tabs active-color='#0050A5' :list="list" :is-scroll="true" :current="current" @change="change"></u-tabs>
			</view>
		</u-sticky>
		<view class="get-height" v-show="showTop">
			<view class="content plr mb-40">
				<!-- 首页轮播 -->
				<bs-swiper @handSwIndex='handSwIndex' :list='swList'></bs-swiper>
			</view>
			<bs-gap top="0" bottom='15'></bs-gap>
			<!-- 热门活动 -->
			<HotActivity :list='newsList' ref='HotActivity'></HotActivity>
			<bs-gap top="16" bottom='40'></bs-gap>
		</view>
		<view class="">
			<bsTextImgList onMsg='暂无收藏' @handDetails='handDetails' :list='collectList' :status='status'></bsTextImgList>
		</view>
	</view>

</template>

<script>
	import bsSwiper from '@/components/bs-swiper/bs-swiper.vue'
	import HotActivity from './components/HotActivity/index.vue'
	import bsTextImgList from '@/components/bs-text-img-list/bs-text-img-list.vue'
	export default {
		components: {
			bsSwiper,
			bsTextImgList,
			HotActivity
		},
		data() {
			return {
				showTop: true,
				navHeight: this.CustomBar * 2,
				scrollTop: 0,
				status: 'nomore',
				paging: {
					page: 1,
					pageSize: 10,
					category: null
				},
				collectList: [],
				list: [{
					name: '推荐',
					id: null
				}, {
					name: '新闻资讯',
					id: '0'
				}, {
					name: '协会动态',
					id: '1'
				}, {
					name: '行业公示',
					id: '5'
				}, {
					name: '文件下载',
					id: '6'
				}, {
					name: '奖项',
					id: '7'
				}],
				swList: [],
				newsList: [],
				current: 0,
				activityTableList: [],
				category: '',
				pages: 0,
			}
		},
		async onReachBottom() {
			if (this.paging.category === null) {
				return
			}
			await this.getMore()
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		async onPullDownRefresh() {
			await this.init()
			await this.initNews()
			this.showTop = true
			this.current = 0
			uni.stopPullDownRefresh();
		},
		onLoad() {
			this.init()
			this.initNews()
		},
		methods: {
			async getMore() {
				if (this.pages == this.paging.page) {
					this.status = 'nomore';
					return
				}
				this.status = 'loading';
				this.paging.page = ++this.paging.page;
				let newsList
				if (this.paging.category == 7) {
					newsList = await this.$u.api.selectAward(this.paging)
				} else {
					newsList = await this.$u.api.selectNewsLis(this.paging)
				}
				this.pages = newsList.pages
				this.collectList = this.collectList.concat(newsList.list)
				this.status = 'loadmore';
			},
			handDetails(item) {
				console.log(item)
				if (item.newsId) {
					uni.navigateTo({
						url: '/pages/my/myCollect/newPage/newPage?newsId=' + item.newsId
					})
				}
				if (item.awardId) {
					uni.navigateTo({
						url: '/pages/richPage/richPage?urlName=selectOneAward&idName=awardId&awardId=' + item.awardId
					})
				}


			},
			async change(index) {
				this.current = index
				this.paging.category = this.list[index].id
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 300
				});
				if (this.list[index].id === null) {
					this.initNews()
					// uni.pageScrollTo({
					// 	scrollTop: 0,
					// 	duration: 300
					// });
					this.showTop = true
					return
				}
				this.showTop = false
				await this.typeInit(this.list[index].id)

			},
			async typeInit(index) {
				this.pages = 0
				this.paging.page = 1
				let res
				//如果等于7 是奖项
				if (index == 7) {
					res = await this.$u.api.selectAward(this.paging)
				} else {
					res = await this.$u.api.selectNewsLis(this.paging)
				}
				this.pages = res.pages
				this.collectList = res.list
				console.log(this.collectList, '分类')
			},
			async init() {
				let res = await this.$u.api.getBanner({
					category: 0
				})
				if (res.length != 0) {
					this.swList = res[0].imgUrlList
				}
				let hotLists = await this.$u.api.hotLists()
				console.log(hotLists, '???')
				this.newsList = hotLists
			},
			async initNews() {
				let res = await this.$u.api.appletsNewsTop()
				console.log(res, '首页新闻列表')
				this.collectList = res.data
			},
			//首页轮播点击事件
			handSwIndex(index) {
				if (this.swList[index].phoneImgSrc) {
					uni.navigateTo({
						url: '/pages/webView/webView?webSrc=' + this.swList[index].phoneImgSrc
					})
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.ceshi1 {
		width: 100%;
		@include my-flex($fd: row, $ai:center, $jc:$bs-sb);
	}

	.content {
		width: 100%;
		padding-top: 30rpx;
	}
</style>
